package com.demo2do.cda.admin.web.controller.system;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.cda.admin.web.interceptor.MenuSetting;
import com.demo2do.core.entity.result.HttpResult;

/**
 * 个人中心
 *
 * @author Ark
 *
 */
@Controller
@RequestMapping("/profile")
@MenuSetting("menu-system")
public class ProfileController {
    
    private static final Logger logger = LoggerFactory.getLogger(ProfileController.class);

    /**
     * 个人中心
     * 
     * @return
     */ 
    @RequestMapping(value = "", method = RequestMethod.GET)
    @MenuSetting("submenu-personal-center")
    public ModelAndView profile() {
        
        ModelAndView modelAndView = new ModelAndView("system/profile/profile");
        
//        Principal principal = principalService.loadByUsername(login.getUsername());
//        
//        modelAndView.addObject("principal",principal);
        
        return modelAndView; 
//    
    } 
    
    /**
     * 重置密码页面
     * 
     * @return
     */
    @RequestMapping(value = "/reset-password", method = RequestMethod.GET)
    public ModelAndView resetPassword() {

        ModelAndView modelAndView = new ModelAndView("system/profile/profile-reset-password");

        return modelAndView;
        
    } 

    /**
     * 重置密码
     * 
     * @return
     */
    @RequestMapping(value = "/reset-password", method=RequestMethod.PATCH, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody HttpResult onResetPassword(){
        
        HttpResult httpResult = new HttpResult();
        
        try {
        
            httpResult.success().message("操作成功");
            
        } catch (Exception e) {
            httpResult.fail("500").message("操作失败");
            logger.error("#editPassword() - edit password fail, exception is [{}]",e);
        }
        
        return httpResult;
    }  
    
    /**
     * go to principal
     * 
     * @return
     */

    @RequestMapping("/principal")
    public String principal() {
        return "home";
    } 
    
}